app.service('couponsDetailAddService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.coupons={
        type:0,
        threshold:0,
        validTimeState:0,
        isOpenRandom:0,
        isOpenRemind:0,
        grantType:0,
        isLimitCount:0,
        isChain:1
    };

    _this_.init=function(){
        _this_.coupons={
            type:0,
            threshold:0,
            validTimeState:0,
            isOpenRandom:0,
            isOpenRemind:0,
            grantType:0,
            isLimitCount:0,
            isChain:1
        };
    }


    //添加优惠卷
    _this_.addCoupons=function($scope){

        if(_this_.coupons.type==0){
            if(_this_.coupons.isOpenRandom==0){
                delete _this_.coupons.startPrice;
                delete _this_.coupons.endPrice;
                delete _this_.coupons.discount;
            }else if(_this_.coupons.isOpenRandom==1){
                delete _this_.coupons.price;
                delete _this_.coupons.discount;
            }
        }else if(_this_.coupons.type==1){
            delete _this_.coupons.startPrice;
            delete _this_.coupons.endPrice;
            delete _this_.coupons.price;
        }

        if(_this_.coupons.isLimitCount==0){
            delete _this_.coupons.limitCount;
        }
        if(_this_.coupons.threshold==0){
            delete _this_.coupons.fullPriceReduction
        }

        if(_this_.coupons.validTimeState==0){
            delete _this_.coupons.validDays;
        }else if(_this_.coupons.validTimeState==1){
            delete _this_.coupons.validStartTime;
            delete _this_.coupons.validEndTime;
        }

        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"coupons",
            data:_this_.coupons
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


}])